<template>
  <div class="app-container">
    <div class="asset-header">
      <div class="img-text">
        <img src="@/assets/bt_img/余额.png" />
        <div class="text">账户余额</div>
      </div>
      <div class="money">
        ￥{{ this.money }}
      </div>
    </div>
    <el-divider></el-divider>
    <div class="text-history">历史记录</div>
    <div class="buttons-row">
      <div class="buttons">
        <el-button
          size="mini"
          @click="setType(null)"
        >全部</el-button>
        <el-button
          size="mini"
          @click="setType(1)"
        >充值</el-button>
        <el-button
          size="mini"
          @click="setType(2)"
        >消费</el-button>
      </div>
      <div class="buttons-right">
        <el-button
          type="primary"
          @click="handleExport"
        >导出Excel</el-button>
      </div>
    </div>

    <el-table :data="AssetList">
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="交易Id" align="center" prop="exchangeMark" />
      <el-table-column label="操作" align="center" prop="type">
        <template slot-scope="scope">
          <p v-if="scope.row.type == '1'">充值</p>
          <p v-if="scope.row.type == '2'">消费</p>
        </template>
      </el-table-column>
      <el-table-column label="金额" align="center" prop="exchangeAmount" />
      <el-table-column label="操作后余额" align="center" prop="balance" />
      <el-table-column label="关联订单" align="center" prop="relateOrder" width="300" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="280" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listAsset, addAsset, assetBalance } from "@/api/asset/asset";

export default {
  name: "Asset",
  data() {
    return {
      // 账户余额
      money: '',
      type: null,
      // 总条数
      total: 0,
      AssetList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: null,
      },
    };
  },
  watch: {
    type(newVal, oldVal){
      if (newVal !== oldVal) {
        this.getList();
      }
    }
  },
  created() {
    this.getList();
    this.getBalance();
  },
  methods: {
    // 获取余额
    getBalance() {
      assetBalance().then(response => {
        this.money = response.data;
      });
    },
    /** 查询代理商消费明细列表 */
    getList() {
      this.queryParams.type = this.type;
      listAsset(this.queryParams).then(response => {
        this.AssetList = response.rows;
        this.total = response.total;
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('system/asset/export', {
        ...this.queryParams
      }, `assetExpend_${new Date().getTime()}.xlsx`)
    },
    // 按钮type
    setType(e) {
      this.type = e;
    }
  }
};
</script>

<style lang="scss" scoped>
  .asset-header {
    margin: 0 10px;
    .img-text {
      display: flex;
      .text {
        margin-left: 8px;
        font-size: 16px;
        color: #999999;
      }
    }
    .money {
      margin-top: 25px;
      font-size: 30px;
      color: #535E83;
    }
  }
  .text-history {
    font-size: 16px;
    color: #333333;
    font-weight: 400;
  }
  .buttons-row {
    overflow: auto;
    margin: 20px 0;
    .buttons {
      float: left;
      display: flex;
      justify-content: space-around;
      align-items: center;
      width: 326px;
      height: 40px;
      background: #dddfe6;
      border-radius: 5px;
      .el-button {
        width: 55px;
        height: 28px;
        border-radius: 5px;
        color: #333333;
        background-color: #dddfe6;
      }
      .el-button:focus, .el-button:active {
        background-color: #535E83;
        color: #FFFFFF;
      }
    }
    .buttons-right {
      float: right;
    }
  }

</style>
